#!/bin/bash

if ! [[ "`pwd`" =~ ^/tmp/.* ]]; then
  echo "not in /tmp"
  echo "bailing out..."
  exit 1
fi
read -s -p "(1/2) Press Enter if you wanna rewrite the committer/author or else C-c"
echo
read -s -p "(2/2) Press Enter again if you wanna rewrite the committer/author"
echo

#src: https://stackoverflow.com/questions/4493936/git-could-i-change-my-name-and-surname-in-all-previous-commits

#using export here to be sure! (didn't test without it!)
export commiterName="ded"
export commiterEmail="inexistentem@il.indeedmyfriend"
export authorName="$commiterName"
export authorEmail="$commiterEmail"


#git filter-branch --commit-filter \
#'if test "$GIT_AUTHOR_NAME" == "OldAuthor Name"; then \
#export GIT_AUTHOR_NAME="$authorName";\
#export GIT_AUTHOR_EMAIL="$authorEmail";\
#export GIT_COMMITTER_NAME="$commiterName";\
#export GIT_COMMITTER_EMAIL="$commiterEmail";\
#fi;\
#git commit-tree "$@"'

git filter-branch --commit-filter \
'export GIT_AUTHOR_EMAIL="$authorEmail";\
export GIT_COMMITTER_EMAIL="$commiterEmail";\
git commit-tree "$@"'
#FIXME: committer name is not changed!

exit 0

#what this does, example:

* commit 0a187cd5e605c23d9565a23e23f32135bbefbf85
  Author:     EmanueL Czirai <emanueLczirai@users.noreply.github.com>
  AuthorDate: Wed Jul 16 08:10:13 2014 +0200
  Commit:     EmanueL Czirai <emanueLczirai@users.noreply.github.com>
  CommitDate: Wed Jul 16 08:10:13 2014 +0200
  
      Initial commit

changed to:

* commit bb928d37853a4bf39c1cec541c4eeb5f1a0d21da
  Author:     EmanueL Czirai <inexistentem@il.indeedmyfriend>
  AuthorDate: Wed Jul 16 08:10:13 2014 +0200
  Commit:     EmanueL Czirai <inexistentem@il.indeedmyfriend>
  CommitDate: Wed Jul 16 08:10:13 2014 +0200
  
      Initial commit


#so for this reason(commit id changed!) I will not rewrite history! (6 june 2015)

